package tongcheng.com.tongcheng.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.bitmap.CircleCrop;

import java.util.List;

import tongcheng.com.tongcheng.ConStans;
import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseViewHolder;
import tongcheng.com.tongcheng.bean.InstallListBean;
import tongcheng.com.tongcheng.ui.yemian.shenfen.activity.install.InstallPeopleDetialActivity;
import tongcheng.com.tongcheng.utils.GlideApp;

/**
 * Created by P on 2017/8/7.
 */

public class InstallListAdapter extends RecyclerView.Adapter<InstallListAdapter.InstallListViewHolder> {

    public Context mContext;
    public List<InstallListBean.DataBean> datas;

    public InstallListAdapter(Context context,List<InstallListBean.DataBean> datas) {
        this.mContext = context;
        this.datas = datas;
    }

    @Override
    public InstallListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = View.inflate(mContext, R.layout.item_installlist, null);

        InstallListViewHolder installListViewHolder = new InstallListViewHolder(view);

        return installListViewHolder;
    }

    @Override
    public void onBindViewHolder(InstallListViewHolder holder, int position) {
        final InstallListBean.DataBean dataBean = datas.get(position);
        holder.installitem_body.setText(dataBean.record);//备注
        holder.installitem_fen.setText("信用积分:" + dataBean.credit_score);//信用积分
        holder.installitem_name.setText(dataBean.user_name);//用户名
        GlideApp.with(mContext).load(ConStans.BaseUrl_Test_url + dataBean.avatar).transform(new CircleCrop())
                .placeholder(R.mipmap.touxiang).error(R.mipmap.touxiang).into(holder.installitem_icon);//加载头像



        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(mContext, InstallPeopleDetialActivity.class);
                intent.putExtra("id", dataBean.id);
                intent.putExtra("qianyue", dataBean.is_sign);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class InstallListViewHolder extends BaseViewHolder{

        public TextView installitem_fen,installitem_name, installitem_body;
        public ImageView installitem_icon;

        public InstallListViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void init(View itemview) {
            installitem_fen= itemview.findViewById(R.id.installitem_fen);
            installitem_name= itemview.findViewById(R.id.installitem_name);
            installitem_body=   itemview.findViewById(R.id.installitem_body);
            installitem_icon=   itemview.findViewById(R.id.installitem_icon);
        }
    }

}
